package com.blue.seata.storage.config;

import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * ribbon负载均衡策略自定义:IRule的实现类即所有策略
 *
 * @author liulei
 * @version 1.0
 */
@Configuration
public class RibbonConfiguration {

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Bean
    public IRule ribbonRule(){
        // 轮询策略[可以定义服务轮询的起始位置]
        return new RoundRobinRule(new BaseLoadBalancer());
    }

}
